package cn.hchaojie.camp.day07;

import java.util.Objects;

// 为什么把成员遍历定义成私有的，然后添加get和set方法
// 方便做额外的、特殊的处理


public class Employee implements Comparable<Employee> {
	// 公共常量
	
	public String name;
	public String lastName;
	
	protected double salary;
	
	public Employee() {
		
	}
	
	public Employee(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}

	protected void print() {
		System.out.println("");
	}
	
	// 没有修饰符，默认就是包访问权限
	// 只有在同一个包内，才能访问
	void foo() {
		System.out.println("foo...");
	}
	
	final void bar() {
		System.out.println("bar...");
	}
	
	private int age;

	public String getName() {
		return lastName + name;
	}

	public void setName(String name) {
		this.name = name.toLowerCase();
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}
	

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Employee [name=");
		builder.append(name);
		builder.append(", lastName=");
		builder.append(lastName);
		builder.append(", salary=");
		builder.append(salary);
		builder.append(", age=");
		builder.append(age);
		builder.append("]");
		return builder.toString();
	}

	// 散列
	
//	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + age;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

//	@Override
//	public boolean equals(Object obj) {
//		if (this == obj)
//			return true;
//		if (obj == null)
//			return false;
//		if (getClass() != obj.getClass())
//			return false;
//		Employee other = (Employee) obj;
//		if (age != other.age)
//			return false;
//		if (name == null) {
//			if (other.name != null)
//				return false;
//		} else if (!name.equals(other.name))
//			return false;
//		return true;
//	}

	@Override
	public int compareTo(Employee o) {
		// 做特殊处理
		if (o == null) return -1;
		
		return this.age - o.age;
	}
	
	

//	@Override
//	public boolean equals(Object obj) {
//		if (this == obj)
//			return true;
//		if (obj == null)
//			return false;
//		if (getClass() != obj.getClass())
//			return false;
//		Employee other = (Employee) obj;
//		if (age != other.age)
//			return false;
//		if (lastName == null) {
//			if (other.lastName != null)
//				return false;
//		} else if (!lastName.equals(other.lastName))
//			return false;
//		if (name == null) {
//			if (other.name != null)
//				return false;
//		} else if (!name.equals(other.name))
//			return false;
//		if (Double.doubleToLongBits(salary) != Double.doubleToLongBits(other.salary))
//			return false;
//		return true;
//	}
}
